package cn.ymjr.sys.util;


import cn.ymjr.business.dao.SysConstantMapper;
import cn.ymjr.business.entity.SysConstant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * @author tiny
 * @date 2020/9/17 16:31
 * @description
 */
@Service("dictInit")
public class DictInit {

    @Autowired
    private SysConstantMapper constantMapper;

    public static Map<String,Map<String,String>> constantMap = new HashMap<>();

    public void start() {
        initData();
    }

    private void initData(){
        List<SysConstant> sysConstants = constantMapper.selectAll();
        for (SysConstant sysConstant : sysConstants) {
            if(constantMap.get(sysConstant.getConstantCode())==null){
                Map<String,String> map = new HashMap<>();
                map.put(sysConstant.getConstantName(),sysConstant.getConstantValue());
                constantMap.put(sysConstant.getConstantCode(),map);
            }else{
                Map<String, String> map = constantMap.get(sysConstant.getConstantCode());
                map.put(sysConstant.getConstantName(),sysConstant.getConstantValue());
                constantMap.put(sysConstant.getConstantCode(),map);
            }
        }
    }
}
